﻿<%@ WebHandler Language="C#" Class="SIPO.Web.AjaxHandler.Loaddata.getImpositionYearReport" %>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using SIPO.Library.DataAccess.Transaction;
using SIPO.Library.DomainObject.Transaction;
using SIPO.Library.Enum;
using SIPO.Web.Support;
using Newtonsoft.Json.Linq;

namespace SIPO.Web.AjaxHandler.Loaddata
{
    public class getImpositionYearReport : SIPO.Web.BaseHandler
    {
        int debtorId = 0;
        int debtorSectorId = 0;
        int subSubSectorId = 0;
        recImpositionRepo recImpositionDal = new recImpositionRepo(ConfigurationManager.ConnectionStrings["SIPOConn"].ConnectionString);
        public override void ProcessRequest(HttpContext context)
        {
            base.ProcessRequest(context);

            if (context.Request.Params["debtorid"] != null)
                debtorId = Convert.ToInt32(context.Request.Params["debtorid"]);
            //if (context.Request.Params["debtorsectorid"] != null)
            //    debtorSectorId = Convert.ToInt32(context.Request.Params["debtorsectorid"]);
            if (context.Request.Params["subsubsectorid"] != null)
                subSubSectorId = Convert.ToInt32(context.Request.Params["subsubsectorid"]);
            recImposition getDectorSectorId = recImpositionDal.GetByDebtorIdAndSubSubSectorId(debtorId, subSubSectorId);
            if (getDectorSectorId != null)
                debtorSectorId = getDectorSectorId.DebtorSectorID;
            List<recImposition> recImpositions = new List<recImposition>();
            recImposition obj = new recImposition();
            recImpositions = recImpositionDal.GetByListDebtorSectorId(debtorSectorId);
            if (recImpositions.Count > 1)
                obj = recImpositionDal.GetByDebtorSectorId(debtorSectorId, false);
            else
                obj = recImpositionDal.GetByDebtorSectorId(debtorSectorId, true);
            int currentTahunLapKeuYear;
            if (obj != null)
                currentTahunLapKeuYear = obj.YearReport;
            else
                currentTahunLapKeuYear = DateTime.Now.Year - 1;
            int nextYear = DateTime.Now.Year + 1;

            List<recImposition> impositions = new List<recImposition>();
            for (int i = currentTahunLapKeuYear; i < nextYear; i++)
            {
                recImposition t = new recImposition();
                t.YearReport = (short)i;
                impositions.Add(t);
                t.Dispose();
            }

            var result = impositions;
            context.Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(result));
        }

        public override bool IsReusable
        {
            get
            {
                return false;
            }
        }

    }
}